layui.use(['form','layer'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
				table=layui.table,
        $ = layui.jquery;
		
		form.verify({
			top: function(value, item){ 
				if(value>20 || value < 1){
					return "不能大于20，且小于1"
				}
			}
		})
		const tableName=new Vue({
			el: '#selectTableName',
			data:{
				all_data:[],
				tableIns:null
			},
			methods:{
				getAllTableNames:function(){
					this.$http.post(global_url+'/admin/ranking/table/all')
						.then(
						response=>{
							this.all_data=response.body.datas
							setTimeout(function(){
								form.render('select');
							},100);
							
						},					
						response=>{
						
						})
				},
				addRanking:function(data){
					this.$http.post(global_url+'/admin/ranking/add',data)
						.then(
						response=>{
							if(response.body.msg=="success"){
								//刷新父页面
								parent.location.reload();
								layer.msg("success!!!")
							}
						},					
						response=>{
						
						})
				}
				
			}})
	tableName.getAllTableNames()
	
	
	form.on("submit(addRanking)",function(data){

		data={
			"name":$(".name").val(),
			"rtid":data.field.selectTableName,
			"rule":data.field.sort,
			"state":data.field.state,
			"top":$(".top").val()
		}
		tableName.addRanking(data)
		// selectType.addType(category)
		return false;
	})
	
	
	
})